-- global_value_damage
-- create by shuzy
-- 技能：全体伤害。对地牢中所有怪物造成固定伤害
-- 目前支持如下配置：
-- 1、global_value_damage(500)：对场上所有敌人造成500的伤害

return {
    apply = function(source, target, skillId, round, para, extra)
        -- 伤害
        local damage = para[1];

        -- 4. 遍历所有的怪
        -- 总伤害
        local totalDamage = 0;
        for p = 1, GRID_SIZE do
            local grid = DungeonM.getGridByPos(p);
            local monster = grid.monster;

            repeat

                -- 是未死亡的怪物
                if  not grid:isOpened() or
                    not monster or
                    grid.monster:isDead() then
                    break;
                end

                -- 增加命中动作
                if SkillM.getSequence(monster) == nil then
                    SkillM.getSequenceList()[monster] = CastSequence.create(source, monster, skillId);
                end

                SkillM.getSequence(monster):hit(source, monster, skillId);

                -- 受创
                CombatM.receiveDamage(source, monster, damage, skillId, extra);

                totalDamage = totalDamage + damage;

            until true;
        end

        -- 如果是玩家，抛出攻击结果事件
        if source.type == OBJECT_TYPE_USER then
            EventMgr.fire(event.HERO_ATTACK_RESULT, { ["damage"] = totalDamage, ["extra"] = extra});
        end

        -- 作用目标
        return ret;
    end,

    parse = function(desc)
        local arr = string.explode(desc, ",");
        return { tonumber(arr[1]), };
    end,

    -- 解析技能描述
    parseDesc = function(source, skillId, desc, para)
        local damage = para[1];
        desc = string.gsub(desc, "{global_damage}", damage);
        return desc;
    end,
};
